Public Class MailForm

  Private Sub MailForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SubjectTextBox.Text = "Test Message on " + DateTime.Now.ToString
  End Sub

  Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
    Dim mailer As New dotNetTips.Utility.Net.Mailer(Me.ServerTextBox.Text)

    Me.StatusLabel.Text = "Sending Message..."

    Try

      mailer.SendMail(New dotNetTips.Utility.EmailAddress(Me.FromTextBox.Text), Me.SubjectTextBox.Text, Me.MessageTextBox.Text, False, dotNetTips.Utility.Net.Mailer.CreateEmailAddressList(Me.ToTextBox.Text))

      Me.StatusLabel.Text = "Message Sent."

    Catch ex As Exception
      MessageBox.Show(ex.Message)
    End Try

  End Sub

  Private Sub SendAsyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendAsyncButton.Click

    Dim mailer As New dotNetTips.Utility.Net.Mailer(Me.ServerTextBox.Text)

    Me.StatusLabel.Text = "Sending Message..."

    Try

      AddHandler mailer.SendMailAsyncCompleted, AddressOf Me.SendMailAsyncCompleted

      mailer.SendMailAsync(New dotNetTips.Utility.EmailAddress(Me.FromTextBox.Text), Me.SubjectTextBox.Text, Me.MessageTextBox.Text, False, dotNetTips.Utility.StringHelper.CreateGuid, dotNetTips.Utility.Net.Mailer.CreateEmailAddressList(Me.ToTextBox.Text))

    Catch ex As Exception
      MessageBox.Show(ex.Message)
    End Try

  End Sub

  Private Sub SendMailAsyncCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

    If Not IsNothing(e.Error) Then
      MessageBox.Show(e.Error.Message)
    Else
      Me.StatusLabel.Text = "Message Sent Async."
    End If

  End Sub
End Class